﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ZFine.Application.Project;
using ZFine.Code;

namespace Logiv.WEB.Areas.Project.Controllers
{
    public class WorkPlanController : BaseController
    {
        PathwayApp pathwayapp=new PathwayApp();
        private GudaoCarApp gudaocarApp = new GudaoCarApp();
        private WorkPlanApp workplanApp = new WorkPlanApp();
        // GET: Project/WorkPlan
        public override ActionResult Index()
        {
            var gudao = pathwayapp.GetListN();
            ViewBag.gudaolist = gudao;
            var gudaolist = pathwayapp.GetList(f => f.State == true).OrderBy(f=>f.ShowSort);
            ViewBag.gudaolists = gudaolist.ToJson();
            return View();
        }
        /// <summary>
        /// 获取指定股道中的车信息
        /// </summary>
        /// <param name="gudaoid"></param>
        /// <returns></returns>
        public JsonResult GetGudaocar(string gudaoid)
        {
            var reuslt = gudaocarApp.GetListInclude(f => f.State == true&&f.BelongPathway.F_Id==gudaoid.Trim());//获取当前有效的所有股道上的车
            if (reuslt != null && reuslt.Count > 0)
            {
                return Json(reuslt.ToJson(), JsonRequestBehavior.AllowGet);
            }
            else
            {
                return Json("", JsonRequestBehavior.AllowGet);
            }
        }


        /// <summary>
        /// 创建计划
        /// </summary>
        /// <returns></returns>
        public ActionResult AddCarTrunToPlan()
        {
            string msg = string.Empty;
            int code = 0;
            string data = Request["jsonData"];
            string Planmun= Request["Planmun"];
            string SendTime = Request["SendTime"];
            string SendTime1 = Request["SendTime1"];
            if (!string.IsNullOrEmpty(data))
            {
                List<ClientPlay> objlist = ZFine.Code.Json.ToList<ClientPlay>(data);
                if (objlist != null && objlist.Count > 0)
                {
                  code = workplanApp.SubmitAddplay(objlist, data, Planmun, SendTime, SendTime1, ref msg);
                    if (code >= 0)
                    {
                        msg = "创建计划成功,请到计划任务中执行计划";
                    }
                }
                else
                {
                    code = -1;
                    msg = "转换对象为空";
                }
            }
            else
            {
                code = -1;
                msg = "传入数据为空";
            }
            return Json(new { msg = msg, code = code }, JsonRequestBehavior.AllowGet);
        }
    }
}